﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using LCA.Community.DAL.Model;
using Microsoft.Practices.Unity;
using LCA.Community.DAL.Interfaces;

namespace LCA.Community.Web.Models
{
    public class CommentViewModel
    {
        private string _authorAvatar;

        public CommentViewModel(Comment comment)
        {
            Comment = comment;
        }

        public static List<CommentViewModel> ConvertListComments(List<Comment> comments)
        {
            var viewModels = new List<CommentViewModel>();
            comments.ForEach(c => viewModels.Add(MvcApplication.Container.Resolve<CommentViewModel>(new ParameterOverrides { { "comment", c } })));

            return viewModels;
        }

        public Comment Comment { get; set; }
        public string AuthorAvatar
        {
            get
            {
                if (_authorAvatar == null)
                    _authorAvatar = UsersRepository.GetUserAvatarUrl(Comment.Author);

                return _authorAvatar;
            }
        }

        [Dependency]
        public IUsersRepository UsersRepository { get; set; }
    }
}